package cn.ichiva.common;

import org.springframework.http.HttpStatus;

/**
 * 单字母马甲
 */
public class R<T> extends JsonResult<T>{

    public static R success(){
        R r = new R<>();
        r.setCode(200);
        return r;
    }

    public static <D> R<D> success(D data){
        R<D> r = new R<>();
        r.setCode(200);
        r.setData(data);
        return r;
    }

    public static R error(int code,String msg){
        R r = new R();
        r.setCode(code);
        r.setMsg(msg);
        return r;
    }

    public static R<?> error(Error error) {
        return R.error(error.code,error.msg);
    }

    public static R<?> error(HttpStatus httpStatus) {
        return R.error(httpStatus.value(),httpStatus.getReasonPhrase());
    }
}
